$(function(){
	
	var rolecode = getUrlParam('rolecode');
	$('input[name="rolecode"]').val(rolecode);
	initSelect();
	
	
})


function initSelect(){
	$.ajax({
		url:basePath() + 'menu/queryAll.do',
		type:'get',
		dataType:'json',
		data: {"roleCode":	$('input[name="rolecode"]').val()},
		success:function(data){
			  $('#menu').treeview({
                  data: data,         // 数据源
                  showCheckbox: true,   //是否显示复选框
                  highlightSelected: true,    //是否高亮选中
                  hierarchicalCheck:true,
                  propagateCheckEven:true,
                  emptyIcon: '',    //没有子节点的节点图标
                  expandIcon:'',
                  collapseIcon:'',
                  multiSelect: true
              });
		}
	});
}

function save(){
	var saveParam ={
			roleCode:$('input[name="rolecode"]').val(),
			menuLists:[]
	};
	$.each($('#menu').treeview('getChecked'),function(index,e){
		 var menuId = {};
		 menuId.menuId= e.menuId;
		 saveParam.menuLists.push(menuId);
	})
	$.ajax({ 
		method: 'post',
		url: basePath() + 'menuPermission/save.do',
		data: JSON.stringify(saveParam),
		dataType: "json",
        contentType: "application/json",
		success: function(data){	
			window.wxc.xcConfirm(data.info, window.wxc.xcConfirm.typeEnum.success, {
	    		onOk: function(){
	    			if(data.result == 1){
	    				parent.location.reload();		//刷新数据
	    			} 
	    		}
	    	});
      	}
	});
}